package me.shiqiang.im.linsteners;

import com.aliyun.openservices.ons.api.Producer;
import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.annotation.OnEvent;
import com.fasterxml.jackson.core.JsonProcessingException;
import me.shiqiang.im.enums.MessageCmd;
import me.shiqiang.im.msg.SyncGroupReq;
import me.shiqiang.im.server.ConnectionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author cuishiqiang
 * @date 2017/12/13 上午10:13
 */
@Component("GroupListener")
public class GroupListener extends Listener{
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    StringRedisTemplate redisTemplate;

    @Autowired
    Producer producer;

    @Value("${server.id}")
    private String serverId;

    @Value("${com.tst.rocketmq.producer.topic}")
    private String topic;

    @OnEvent("syncGroupReq")
    public void getGroups(SocketIOClient client, AckRequest request, SyncGroupReq msg) throws JsonProcessingException {
//        logger.info("{}拉取官方群", client.getRemoteAddress());
        SocketIOClient socketIOClient = ConnectionContext.getInstance().nextProcessor();
        if (socketIOClient == null) {
            logger.info("没有消费处理程序");
            return;
        }
        socketIOClient.sendEvent(MessageCmd.SYNC_GROUP_REQ,msg);
    }
}
